<template>
  <div>
    <div>
      <div style="margin-bottom: 5%;"></div>
      <el-card style="margin:0 auto;width: 60%;">
        <div style="margin-bottom: 2%;"></div>
        <div style="font-weight: initial ;font-size: 35px;text-align:center;">修 改 学 院</div>
        <div style="margin-bottom: 5%;"></div>

        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="30%">
          <el-form-item  label="学院编号">
            <el-input
                placeholder="请输入内容"
                v-model="ruleForm.academyId"
                style="width: 40%"
                :disabled="true">
            </el-input>
          </el-form-item>
          <div style="margin-bottom: 4%;"></div>
          <el-form-item label="学院名称" prop="academyName">
            <el-input v-model="ruleForm.academyName" placeholder="例如:XXX学院" style="width: 60%"></el-input>
          </el-form-item>
          <div style="margin-bottom: 4%;"></div>
          <el-form-item label="学院地址" prop="academyAddress">
            <el-input type="textarea" :autosize="{ minRows: 3}" style="width:60%" v-model="ruleForm.academyAddress"></el-input>
          </el-form-item>
          <div style="margin-bottom: 4%;"></div>
          <el-form-item label="学院简介" prop="academySummary">
            <el-input type="textarea" :autosize="{ minRows: 6}" style="width:60%" v-model="ruleForm.academySummary"></el-input>
          </el-form-item>
          <el-form-item>
            <span>禁用 </span>
            <el-switch
                v-model="ruleForm.academyFlag"
                active-color="#13ce66"
                inactive-color="#ff4949"
                active-value="0"
                inactive-value="1">
            </el-switch>
            <span> 启用</span>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
            <el-button style="margin-left:60px" @click="returnPage()">返回</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm:{
        academyId:'',
        academyName:'',
        academyAddress:'',
        academySummary:'',
        academyFlag:''
      },
      rules: {
        academyName: [
          { required: true, message: '请输入学院名称', trigger: 'blur' },
          { min: 2, max: 40, message: '请输入 2 到 40 个字符!', trigger: 'blur' }
        ],
        academyAddress: [
          { min: 0, max: 120, message: '您输入的学院地址太长了!', trigger: 'blur' }
        ],
        academySummary: [
          { min: 0, max: 400, message: '您输入的学院简介太长了!', trigger: 'blur' }
        ]
      }
    }
  },
  created(){
    this.ruleForm.academyId = this.$route.params.academyId
    let path = 'http://localhost:8081/academy/selectOneAcademy';
    this.$ajax.post(path,this.ruleForm).then(res=>{
      this.ruleForm = res.data.obj;
    })
  },
  methods:{
    submitForm(formName){
      this.$refs[formName].validate((valid) => {//校验格式
        if (valid) {//格式校验通过
          console.log(this.ruleForm);
          let path = 'http://localhost:8081/academy/updateOneAcademy';
          this.$ajax.post(path,this.ruleForm).then(res=>{
            if(res.data.status === 0){
              this.$message({
                showClose: true,
                message: res.data.message,
                type: 'success'
              });
              this.returnPage();
            }
          })
        }
      });
    },
    returnPage(){
      this.$router.push('/admin/academyMGMT');
    }
  }
}
</script>

<style scoped>

</style>